package com.supersit.greensproject.activity;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;

import com.supersit.greensproject.R;
import com.supersit.greensproject.adapter.FragmentAdapter;
import com.supersit.greensproject.application.MyApplication;
import com.supersit.greensproject.resources.Resources;

import com.supersit.greensproject.view.MyTitleBar;
import com.supersit.greensproject.view.SyncHorizontalScrollView;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.util.List;

/**
 * Created by cong on 2016/7/14.
 */
@ContentView(R.layout.activity_fragment)
public class FragmentActivity extends BaseActivity {
    private List<Fragment> fragmentList;
    public String[] tabTitle;
    private FragmentAdapter fragmentAdapter;
    private Context context;
    // 导航栏
    @ViewInject(R.id.id_demand_title_tab)
    private RelativeLayout rl_nav;

    @ViewInject(R.id.vp_demand_body)
    private ViewPager mViewPager;

    @ViewInject(R.id.mHsv)
    private SyncHorizontalScrollView mHsv;

    @ViewInject(R.id.rg_nav_content)
    private RadioGroup rg_nav_content;

    @ViewInject(R.id.iv_nav_indicator)
    private ImageView iv_nav_indicator;

    @ViewInject(R.id.iv_nav_left)
    private ImageView iv_nav_left;

    @ViewInject(R.id.iv_nav_right)
    private ImageView iv_nav_right;
    //标题栏
    private MyTitleBar myTitleBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        x.view().inject(this);
        context = this;
        setMyTitleBar();
        initVariable();
        bindListener();
    }

    private void initVariable() {
        fragmentList = MyApplication.getFragmentList();
        tabTitle = new String[]{getString(R.string.select_data), getString(R.string.entering_data)};    //标题
        fragmentAdapter = new FragmentAdapter(getSupportFragmentManager(), fragmentList, tabTitle);
        mViewPager.setAdapter(fragmentAdapter);
        mHsv.setSomeParam(rl_nav, iv_nav_left,
                iv_nav_right, this, tabTitle, iv_nav_indicator, rg_nav_content, mViewPager);
    }

    private void setMyTitleBar() {
        Bundle b = getIntent().getExtras();
        int typeNo = b.getInt("baseType");
        myTitleBar = new MyTitleBar(context, findViewById(R.id.fragment_title));
        myTitleBar.setTitleText(Resources.subjectBaseTitles[typeNo]);
        myTitleBar.setChildVisibility(false, myTitleBar.getmImgRight());
    }

    private void bindListener() {
        myTitleBar.setImg1Listener(onClickListener);
    }

    private View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.title_bar_left:
                    finish();
                    break;
            }
        }
    };
}
